﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class Class4
    {

        [DllImport("Termb.dll", EntryPoint = "CVR_InitComm", CharSet = CharSet.Ansi)]
        public static extern int A([In] int obj0);

        [DllImport("Termb.dll", EntryPoint = "CVR_Authenticate", CharSet = CharSet.Ansi)]
        public static extern int A();

        [DllImport("Termb.dll", EntryPoint = "CVR_AuthenticateForNoJudge", CharSet = CharSet.Ansi)]
        public static extern int a();

        [DllImport("Termb.dll", EntryPoint = "CVR_Read_Content", CharSet = CharSet.Ansi)]
        public static extern int a([In] int obj0);

        [DllImport("Termb.dll", EntryPoint = "CVR_Read_FPContent", CharSet = CharSet.Ansi)]
        public static extern int B();

        [DllImport("Termb.dll", EntryPoint = "CVR_FindCard", CharSet = CharSet.Ansi)]
        public static extern int b();

        [DllImport("Termb.dll", EntryPoint = "CVR_SelectCard", CharSet = CharSet.Ansi)]
        public static extern int C();

        [DllImport("Termb.dll", EntryPoint = "CVR_CloseComm", CharSet = CharSet.Ansi)]
        public static extern int c();

        [DllImport("Termb.dll", EntryPoint = "GetCertType", CharSet = CharSet.Ansi)]
        public static extern int A([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetPeopleName", CharSet = CharSet.Ansi)]
        public static extern int a([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetPeopleChineseName", CharSet = CharSet.Ansi)]
        public static extern int B([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetPeopleNation", CharSet = CharSet.Ansi)]
        public static extern int b([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetNationCode", CharSet = CharSet.Ansi)]
        public static extern int C([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetPeopleBirthday", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int c([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetPeopleAddress", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int D([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetPeopleIDCode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int d([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetDepartment", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int E([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetStartDate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int e([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetEndDate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int F([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetPeopleSex", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int f([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "CVR_GetSAMID", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int A([In] ref byte obj0);

        [DllImport("Termb.dll", EntryPoint = "GetBMPData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int G([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "GetJpgData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int g([In] ref byte obj0, [In] ref int obj1);

        [DllImport("Termb.dll", EntryPoint = "Getbase64BMPData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int H([In] ref byte obj0, [In] ref int obj1);





        public static string xxx()
        {
            Unk211.b();
            try
            {
                int num1 = 0;
                int num2 = 0;
                for (int index = 1001; index <= 1016; ++index)
                {
                    num1 = ConsoleApp1.Class4.A(index);
                    if (num1 == 1)
                        break;
                }

                for (int index = 1; index <= 16; ++index)
                {
                    num2 = ConsoleApp1.Class4.A(index);
                    if (num2 == 1)
                        break;
                }

                //if (num1 != 1 && num2 != 1)
                    //C.A(Unk211.aP(), Unk211.b());
                int num3 = 0;
                if (ConsoleApp1.Class4.a() == 1)
                {
                    int num4 = ConsoleApp1.Class4.B();
                    if (num4 == 1)
                    {
                        //C.A(Unk211.aR(), Unk211.b());
                        string str1 = AppDomain.CurrentDomain.BaseDirectory + Unk211.ar(); //实际值为BF1B0F9E89AA3D85731571C76F5A7729
                        byte[] numArray1 = new byte[40960];
                        int num5 = 40960;
                        ConsoleApp1.Class4.g(ref numArray1[0], ref num5);
                        MemoryStream memoryStream = new MemoryStream();
                        for (int index = 0; index < num5; ++index)
                            memoryStream.WriteByte(numArray1[index]);
                        //Image image = Image.FromStream((Stream)memoryStream);
                        //C.A(Unk211.aS() + str1, Unk211.b());
                        //string str2 = D.A(image);
                        string str2 = "图片base64";

                        byte[] bytes1 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.a(ref bytes1[0], ref num5);      //姓名GetPeopleName
                        byte[] numArray2 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.B(ref numArray2[0], ref num5);  //中文姓名GetPeopleChineseName
                        byte[] bytes2 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.d(ref bytes2[0], ref num5);      //身份证号码GetPeopleIDCode
                        byte[] bytes3 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.b(ref bytes3[0], ref num5);      //民族GetPeopleNation
                        byte[] numArray3 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.C(ref numArray3[0], ref num5);   //民族编码GetNationCode
                        byte[] bytes4 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.e(ref bytes4[0], ref num5);      //起始日期GetStartDate
                        byte[] bytes5 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.c(ref bytes5[0], ref num5);      //生日GetPeopleBirthday
                        byte[] bytes6 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.D(ref bytes6[0], ref num5);      //户籍地址GetPeopleAddress
                        byte[] bytes7 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.F(ref bytes7[0], ref num5);      //到期时间GetEndDate
                        byte[] bytes8 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.E(ref bytes8[0], ref num5);      //发证部门GetDepartment
                        byte[] bytes9 = new byte[128];
                        num5 = 128;
                        ConsoleApp1.Class4.f(ref bytes9[0], ref num5);      //性别GetPeopleSex
                        byte[] bytes10 = new byte[128];
                        ConsoleApp1.Class4.A(ref bytes10[0]);               //设备ID SAMID

                        string str3 = bb();         //动态计算： 加密后字符串A1CBAA83DDADC533267D1958E4C7F036BF1B0F9E89AA3D85731571C76F5A7729需要使用Ab.A_b_a(a)+ Code211.C(DateTime.Now.ToString(Unk211.L()))
                        string str4 = Unk211.@as();
                        string str5 = Unk211.aT() + str2 + Unk211.at() + Unk211.aU() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes1)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.au() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes9)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.aV() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes3)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.av() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes5)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.aW() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes6)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.aw() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes2)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.aX() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes8)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.ax() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes4)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.aY() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes7)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.ay() +
                                      Encoding.GetEncoding(Unk211.ap()).GetString(bytes10)
                                          .Replace(Unk211.aQ(), Unk211.b()).Trim() + Unk211.at() + Unk211.aZ() + str3 +
                                      Unk211.az();
                        string str6 = str4 + Unk211.BA() + Code211.b(str5.Replace(Unk211.Ba(), Unk211.b())) + Unk211.BA() +
                                      Unk211.BB();
                        ConsoleApp1.Class4.c();
                        return str6.Replace(Unk211.Ba(), Unk211.b());
                    }

                    string str = Unk211.Bb();
                    if (num4 == 4)
                        str = Unk211.BC();
                    ConsoleApp1.Class4.c();
                    //C.A(Unk211.Bc(), Unk211.b());
                    return Unk211.BD() + str + Unk211.az();
                }

                ConsoleApp1.Class4.c();
                string str7 = Unk211.Bd();
                if (num3 == 4)
                    str7 = Unk211.BC();
                if (num3 == 2 || num3 == 3)
                    str7 = Unk211.BE();
                ConsoleApp1.Class4.c();
                //C.A(Unk211.Be(), Unk211.b());
                return Unk211.BD() + str7 + Unk211.az();
            }
            catch (Exception ex)
            {
                //C.A(Unk211.BF() + ex.ToString(), Unk211.b());
                return Unk211.Bf();
            }
        }



        public static string bb()
        {
           /* string str1 = Code211.C(DateTime.Now.ToString(Unk211.L()));
            string str2 = A.b.a(A.b.A(false));
            string path = AppDomain.CurrentDomain.BaseDirectory + Unk211.l();
            if (File.Exists(path))
            {
                string str3 = File.ReadAllText(path);
                if (str3 != Unk211.b())
                {
                    try
                    {
                        str2 = str3.Substring(0, 32);
                    }
                    catch (Exception ex)
                    {
                        A.C.A(Unk211.M() + str3 + Unk211.m() + ex.ToString(), Unk211.b());
                    }
                }
            }
            return str2 + str1;*/
           return "";
        }



    }


    
}
